<div class="my-account form-container">
	<div class="col-left sidebar">
		<div class="block block-account">
			<div class="block-title">
				<strong>
					<span><?=lang('my_account')?></span>
				</strong>
			</div>
			<div class="block-content">
				<ul>
					<li >
						<a href="<?=site_url('user/dashboard')?>">
						<?=lang('my_dashbord')?>
						</a>	
					</li>
					<li>
						<a href="<?=site_url('user/my_account/')?>">
							<?=lang('account_info')?>
						</a>
					</li>
					<li>
						<a href="<?=site_url('user/my_address/')?>">
							<?=lang('my_address')?>
						</a>
					</li>
					<li class="current">
						<strong>
						<?=lang('address_book')?>
						</strong>	
					</li>
					<li>
						<a href="<?=site_url('user/my_orders/')?>">
							<?=lang('my_orders')?>
						</a>
					</li>
					<li >
						<a href="<?=site_url('user/newsLetter')?>">
						<?=lang('newsletter')?>
						</a>	
					</li>
					<li class="last">
						<a href="<?=site_url('user/logout/')?>">
							<?=lang('logout')?>
						</a>
					</li>
				</ul>
			</div>
		</div>
	</div>
	<div class="col-main">
		
			<h1 style="padding:10px">
				<?=($new_address? lang('add_new_address') : lang('edit_address') )?>
			</h1>
			<div class="formErrors">
					<?php echo validation_errors(); ?>
			</div>
			<ul class="form-list">
		        <form action="<?=site_url('user/add_new_address')?>" method="post" id="mynewaddressFrm">
		        <li id="billing-new-address-form">
		               <ul>
		               <li>
		               	<ul>
							<li class="control left">
								<input class="radio validation-passed" type="radio"  value="1 <?=$address_from_db->natural_person == 1 ? 'checked="on"': ''?> name="natural_person">
								<label><?=lang('natural_person')?>&nbsp;&nbsp;&nbsp;</label>
							
								<input class="radio validation-passed" type="radio" checked="checked" value="0" <?=$address_from_db->natural_person == 0 ? 'checked="on"': ''?> name="natural_person">
								<label ><?=lang('legal_entity')?></label>
						   </li>
						</ul>
						<div class="clear"></div>
		                <div class="customer-name">
						    <div class="field name-first_name">
						        <label for="billing:first_name" class="required"><em>*</em><?=lang('first_name')?></label>
						        <div class="input-box">
						            <input type="text" id="billing:first_name" name="first_name" value="<?=($address_from_db->first_name) ? $address_from_db->first_name : ''?>" title="First Name" class="input-text required-entry"  />
						        </div>
						    </div>
						    <div class="field name-last_name">
						        <label for="billing:last_name" class="required"><em>*</em><?=lang('last_name')?></label>
						        <div class="input-box">
						            <input type="text" id="billing:last_name" name="last_name" value="<?=($address_from_db->last_name) ? $address_from_db->last_name : ''?>" title="Last Name" class="input-text required-entry"  />
						        </div>
						    </div>
						</div>
						</li>
		                <li class="fields">
		                    <div class="field">
		                        <label for="billing:company"><?=lang('company')?></label>
		                        <div class="input-box">
		                            <input type="text" id="billing:company" name="company" value="<?=($address_from_db->company) ? $address_from_db->company : ''?>" title="Company" class="input-text" />
		                       	</div>
		                    </div>
		                        </li>
		                <li class="wide">
		                    <label for="billing:address" class="required"><em>*</em><?=lang('address')?></label>
		                    <div class="input-box">
		                        <textarea title="Street Address" name="address" id="billing:address" class="textarea required-entry" ><?=($address_from_db->address) ? $address_from_db->address : ''?></textarea>
		                    </div>
		                </li>
		                <li class="fields">
		                    <div class="field">
		                        <label for="billing:city" class="required"><em>*</em><?=lang('city')?></label>
		                        <div class="input-box">
		                            <input type="text" title="City" name="city" value="<?=($address_from_db->city) ? $address_from_db->city : ''?>" class="input-text required-entry" id="billing:city" />
		                        </div>
		                    </div>
		                    <div class="field">
		                        <label for="billing:state_provide" class="required"><em>*</em><?=lang('state_provide')?></label>
		                        <div class="input-box">
		                            <input type="text" id="billing:state_provide" name="state_provide" value="<?=($address_from_db->state_provide) ? $address_from_db->state_provide : ''?>" class="input-text" />
		                        </div>
		                    </div>
		                </li>
		                <li class="fields">
		                    <div class="field">
		                        <label for="billing:postcode" class="required"><em>*</em><?=lang('zip_code_postal')?></label>
		                        <div class="input-box">
		                            <input type="text" title="Zip/Postal Code" name="postcode" id="billing:postcode" value="<?=($address_from_db->postcode) ? $address_from_db->postcode : ''?>" class="input-text validate-zip-international required-entry" />
		                        </div>
		                    </div>
		                    <div class="field">
		                        <label for="billing:country_id" class="required"><em>*</em><?=lang('country')?></label>
		                        <div class="input-box">
		                            <select class="country_id" id="billing:country_id" name="country_id" style="width:258px">
									<?php
										foreach ($countries as $country) {
											$flagUrl = IMAGES_URL . 'flags/' . $country->flag;
											if ($sel_country == $country->id) {
												echo '<option selected value="' . $country->id .  '">' . ucfirst($country->name) . '</option>';
											} 
											else {
												echo '<option value="' . $country->id .  '">' . ucfirst($country->name) . '</option>';
											}
										}
									?>
									</select>
		                    	</div>
		                    </div>
		                </li>
		                <li lang="fields">
		                    <div class="field">
		                        <label for="billing:tel_number" class="required"><em>*</em><?=lang('tel_number')?></label>
		                        <div class="input-box">
		                            <input type="text" name="tel_number" value="<?=($address_from_db->tel_number) ? $address_from_db->tel_number : ''?>" title="tel_number" class="input-text required-entry" id="billing:tel_number" />
		                        </div>
		                    </div>
		                    <div class="field">
		                        <label for="billing:fax"><?=lang('fax')?></label>
		                        <div class="input-box">
		                            <input type="text" name="fax" value="<?=($address_from_db->fax) ? $address_from_db->fax : ''?>" class="input-text" id="billing:fax" />
		                        </div>
		                    </div>
		                </li>
					</ul>
					<ul>
						<li class="control">
							<input  class="radio validation-passed" type="radio" title="Ship to this address"<?=($address_from_db->type == 3) ?'checked="on"': ''?> value="3" name="use_for_shipping">
							<label for="billing:use_for_shipping_yes"><?=lang('use_for_billing')?></label>
						</li>
					    <li class="control">
							<input class="radio validation-passed" type="radio"  title="Ship to different address"  <?=($address_from_db->type == 4) ?'checked="on"': ''?> value="4" name="use_for_shipping">
							<label for="billing:use_for_shipping_no"><?=lang('use_for_shipping')?></label>
					   </li>
					</ul>
					<input type="hidden" name="address_id" value ="<?=($address_from_db->id) ? $address_from_db->id : ''?>"/>
		     	</form>
             </ul>
             
             <span style="color: rgb(255, 0, 0); height: 30px; line-height: 43px;" class="right">* <?=lang('required_filds_lang')?></span>
           <div class="clear"></div>
			<br><br>
			<div class="button" style="float:right;" id="btn-save-address">
				<?=lang('save')?>
			 </div>			
	</div>
	<div class="clear"></div>	
	<br>
    <br>
    <br>
<script type="text/javascript">
$(document).ready(function() {
	$('#btn-save-address').click(function(){
		 if ($("#mynewaddressFrm").valid()){
			$('#mynewaddressFrm').submit();
		 }

	});
	$("#mynewaddressFrm").validate({
		rules: {
			"first_name" : {
	        	required: true
	        },
	        "last_name": {
	        	required: true
	        },
	        "address": {
		    	required: true
		    },
		    "city": {
	       		required: true
		    },
		    "state_provide": {
	       		required: true
		    },
		    "postcode": {
	       		required: true,
	       		number: true
		    },
		    "country_id": {
	       		required: true
		    },
		    "tel_number": {
	       		required: true,
	       		number: true
		    },
		    "fax": {
	       		number: true
		    }
		}
	});
});
	
	</script>
	
	
